﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentApartMentManage
{
    public partial class SeekAMTInfo : Form
    {
        public SeekAMTInfo()
        {
            InitializeComponent();
        }

        private void SeekAMTInfo_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = DataShow.show("select * from 公寓楼房信息表");
            dataGridView2.DataSource = DataShow.show("select * from 公寓信息表");
            comboBox2.ValueMember = "管理员ID";
            comboBox2.DisplayMember = "管理员ID";
            comboBox2.DataSource = sqlHelper.GetTable("select distinct 管理员ID from 公寓管理员信息表");
            comboBox3.ValueMember = "公寓楼号";
            comboBox3.DisplayMember = "公寓楼号";
            comboBox3.DataSource = sqlHelper.GetTable("select distinct 公寓楼号 from 公寓楼房信息表");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = string.Format("select * from 公寓楼房信息表 where 公寓楼号 like '{0}%' and 公寓楼名 like '{1}%' and 公寓位置 like '{2}%' and 公寓类别 = {3} and 楼层数 = {4} and 宿舍数量 = {5} and 管理员ID ='{6}'", textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), radioButton1.Checked ? 1 : 0, Convert.ToInt32(textBox4.Text.Trim()), Convert.ToInt32(comboBox1.Text.Trim()), comboBox2.Text.Trim());
                //MessageBox.Show(sql);
                dataGridView1.DataSource = DataShow.show(sql);
                MessageBox.Show("查找楼房信息成功!");
                   
            }
            catch(Exception ex)
            {
                MessageBox.Show("查找失败!");
                return;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你真的要重置输入的信息吗？", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Text = "0";
                comboBox1.Text = "0";
                radioButton1.Checked = true;
                comboBox2.Text = "";
               
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你真的要重置输入的信息吗？", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                textBox5.Clear();
                textBox6.Text = "5";
                textBox7.Text = "500";
                comboBox3.Text = "";
                checkBox3.Checked = false;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = string.Format("select * from 公寓信息表 where 公寓号 like'{0}%' and 公寓楼号 like '{1}%' and 床位数量={2} and 住宿费用={3} and 是否住满={4}", textBox5.Text.Trim(), comboBox3.Text.Trim(), Convert.ToInt32(textBox6.Text.Trim()), Convert.ToInt32(textBox7.Text.Trim()), checkBox3.Checked ? 1 : 0);
                dataGridView2.DataSource = DataShow.show(sql);
                MessageBox.Show("查找宿舍信息成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("查找失败!");
                return;
            }
        }
    }
}
